FROM ubuntu:16.04

MAINTAINER Liu Lu <liulu_heu@qq.com>

# 安装 apt-https 为从清华源下载做准备
# 更新软件源, 否则无法安装 https
RUN apt-get update
RUN apt-get install -y apt-transport-https

# 使用清华apt源, 更新
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse" > /etc/apt/sources.list
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse" >> /etc/apt/sources.list
RUN apt-get update

# 安装 ssh
RUN apt-get install -y openssh-server
# 安装 git
RUN apt-get install -y git

# mkdir -p 上层目录不存在自动创建
RUN mkdir -p /var/run/sshd
RUN mkdir -p /root/.ssh

# 取消 pam 限制
RUN sed -ri 's/session    required    pam_loginuid.so/#session    required    pam_loginuid.so/g' /etc/pam.d/sshd

#配置SSH
#设置ssh远程登陆密码
RUN echo "root:123456" | chpasswd
RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config  
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config  

#复制Rsa文件到相应位置，并赋予脚本可执行权限
ADD authorized_keys /root/.ssh/authorized_keys
ADD run.sh /run.sh
# 脚本权限为可执行
RUN chmod 755 /run.sh

# 开放端口
EXPOSE 22

# 启动容器的命令
CMD ["/bin/bash", "/run.sh"]
